********************************************************************************
*MERGE SEVERAL DATASETS:
*cumulative dataset 2002-2016: ESS1-8e01.dta
*dataset 2018: ESS9e02.dta
*2004 Hungary specific variables: ESS2csHU
*2002 France specific variables: ESS1csFR.sav
*2004 France specific variables: ESS2csFR.sav
********************************************************************************

*set the global for data folder (ESS)
global path ...
*adding 2018_wave9 to unified dataset

use "$path\ESS1-8e01.dta", clear

append using "$path\ESS9e02.dta"

save "$path\ESS_dataset_2002-2018.dta", replace

replace cregion=region if essround==9

*merge HU 2004 specific variables
use "$path\ESS2csHU.dta", clear

foreach var of varlist _all{
	rename `var' `=lower("`var'")'
}
gen essround=2
drop cntry
gen cntry="HU"

save "$path\ESS2csHU_1.dta", replace

use "$path\ESS1-8e01.dta", clear

merge 1:1 idno cntry essround using "$path\ESS2csHU_1", keepusing(emprelhu emprlphu)
drop _merge

save "$path\ESS_dataset_2002-2018.dta", replace

*merge FR 2002 specific variables
import spss using "$path\ESS1csFR.sav", clear

gen essround=1
rename emprlfr emprlfr02
rename emprlpfr emprlpfr02

save "$path\2002_FR_speficic.dta", replace

use "$path\ESS_dataset_2002-2018.dta", clear

merge 1:1 idno cntry essround using "$path\2002_FR_speficic.dta", keepusing(emprlfr emprlpfr)
drop _merge

save "$path\ESS_dataset_2002-2018.dta", replace

*merge FR 2004 specific variables
import spss using "$path\FESS2csFR.sav", clear

gen essround=2
rename emprlfr emprlfr04
rename emprlpfr emprlpfr04

save "$path\2004_FR_specific.dta", replace

use "$path\ESS_dataset_2002-2018.dta", clear

merge 1:1 idno cntry essround using "$path\2004_FR_specific.dta", keepusing(emprlfr emprlpfr)
drop _merge

save "$path\ESS_dataset_2002-2018.dta", replace

tab cntry essround, m


********************************************************************************
********************************************************************************
*CLASS SCHEMA
********************************************************************************
********************************************************************************


*WAVES 1-2-3-4-5

**** 16-Class schema constructed
  *1 Large employers
  *2 Self-employed professionals
  *3 Small business owners with employees
  *4 Small business owners without employees
  *5 Technical experts
  *6 Technicians
  *7 Skilled manual
  *8 Low-skilled manual
  *9 Higher-grade managers and administrators
  *10 Lower-grade managers and administrators
  *11 Skilled clerks
  *12 Unskilled clerks
  *13 Socio-cultural professionals
  *14 Socio-cultural semi-professionals
  *15 Skilled service
  *16 Low-skilled service

**** 8-Class schema constructed
  *1 Self-employed professionals and large employers
  *2 Small business owners
  *3 Technical (semi-)professionals
  *4 Production workers
  *5 (Associate) managers
  *6 Clerks
  *7 Socio-cultural (semi-)professionals
  *8 Service workers

**** 5-Class schema constructed
  *1 Higher-grade service class
  *2 Lower-grade service class
  *3 Small business owners
  *4 Skilled workers
  *5 Unskilled workers

**** Variables used to construct Oesch class schema: iscoco, emplrel, emplno, iscocop, emprelp, emplnop, cntry, essround

****************************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: iscoco, emplrel, emplno
****************************************************************************************

**** Recode occupation variable (isco88 com 4-digit) for respondents

tab iscoco

recode iscoco (missing=-9) if essround<6, copyrest gen(isco_mainjob)
label variable isco_mainjob "Current occupation of respondent - isco88 4-digit"
tab isco_mainjob

**** Recode employment status for respondents

tab emplrel

recode emplrel (missing=9), copyrest gen(emplrel_r)
** SYNTAX G (France 2002 - respondent):
recode emprlfr02 (2 3 4=1)(1=2)(5=3)(6 8 9=9)
replace emplrel_r=emprlfr02 if cntry=="FR" & essround==1
** SYNTAX I (France 2004 - respondent):
recode emprlfr04 (2 3 4=1)(1=2)(5=3)(6 8 9=9)
replace emplrel_r=emprlfr04 if cntry=="FR" & essround==2
** SYNTAX E (Hungary 2004 - respondent):
recode emprelhu (1 4=1)(2=2)(3=3)(6 7 8 9=9)
replace emplrel_r=emprelhu if cntry=="HU" & essround==2
label define emplrel_r ///
1 "Employee" ///
2 "Self-employed" ///
3 "Working for own family business" ///
9 "Missing"
label value emplrel_r emplrel_r
tab emplrel_r

tab emplno

recode emplno (0=0)(1/9=1)(10/10000=2)(missing=0), gen(emplno_r)
label define emplno_r ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_r emplno_r
tab emplno_r


gen selfem_mainjob=.
replace selfem_mainjob=1 if emplrel_r==1 | emplrel_r==9
replace selfem_mainjob=2 if emplrel_r==2 & emplno_r==0
replace selfem_mainjob=2 if emplrel_r==3
replace selfem_mainjob=3 if emplrel_r==2 & emplno_r==1
replace selfem_mainjob=4 if emplrel_r==2 & emplno_r==2
label variable selfem_mainjob "Employment status for respondants"
label define selfem_mainjob ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with 1-9 employees" ///
4 "Self-empl with 10 or more"
label value selfem_mainjob selfem_mainjob
tab selfem_mainjob


*************************************************
* Create Oesch class schema for respondents
*************************************************

gen class16_r = -9 if essround==1 | essround==2 | essround==3 | essround==4 | essround==5

* Large employers (1)

replace class16_r=1 if selfem_mainjob==4


* Self-employed professionals (2)

replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2000 & isco_mainjob <= 2229) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2300 & isco_mainjob <= 2470)

* Small business owners with employees (3)

replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 1000 & isco_mainjob <= 1999)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 3000 & isco_mainjob <= 9333)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2230)

* Small business owners without employees (4)

replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 1000 & isco_mainjob <= 1999)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 3000 & isco_mainjob <= 9333)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2230)

* Technical experts (5)

replace class16_r=5 if (selfem_mainjob==1) & (isco_mainjob >= 2100 & isco_mainjob <= 2213)

* Technicians (6)

replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3100 & isco_mainjob <= 3152)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3210 & isco_mainjob <= 3213)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob == 3434)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 6000 & isco_mainjob <= 7442)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8310 & isco_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8324 & isco_mainjob <= 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8332 & isco_mainjob <= 8340)

* Low-skilled manual (8)

replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8000 & isco_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8320 & isco_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob == 8331)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 9153 & isco_mainjob <= 9333)

* Higher-grade managers and administrators (9)

replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 1000 & isco_mainjob <= 1239)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 2400 & isco_mainjob <= 2429)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob == 2441)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob == 2470)

* Lower-grade managers and administrators (10)

replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 1300 & isco_mainjob <= 1319)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3400 & isco_mainjob <= 3433)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3440 & isco_mainjob <= 3450)

* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4000 & isco_mainjob <= 4112)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4114 & isco_mainjob <= 4210)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4212 & isco_mainjob <= 4222)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4113)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4211)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4223)

* Socio-cultural professionals (13)

replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2220 &  isco_mainjob <= 2229)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2300 &  isco_mainjob <= 2320)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2340 &  isco_mainjob <= 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2430 &  isco_mainjob <= 2440)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2442 &  isco_mainjob <= 2443)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2445)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2451)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2460)

* Socio-cultural semi-professionals (14)

replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2230)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2330 & isco_mainjob <= 2332)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2444)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2446 & isco_mainjob <= 2450)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2452 & isco_mainjob <= 2455)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3220 & isco_mainjob <= 3224)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3226)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3229 & isco_mainjob <= 3340)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3460 & isco_mainjob <= 3472)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3480)

* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3225)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 3227 & isco_mainjob <= 3228)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 3473 & isco_mainjob <= 3475)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5000 & isco_mainjob <= 5113)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5122)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5131 & isco_mainjob <= 5132)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5140 & isco_mainjob <= 5141)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5143)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5160 & isco_mainjob <= 5220)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 8323)

* Low-skilled service (16)

replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5120 & isco_mainjob <= 5121)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5123 & isco_mainjob <= 5130)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5133 & isco_mainjob <= 5139)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5142)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5149)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5230)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 9100 &  isco_mainjob <= 9152)

mvdecode class16_r, mv(-9)
label variable class16_r "Respondent's Oesch class position - 16 classes"
label define class16_r ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_r class16_r
tab class16_r

recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)
label variable class8_r "Respondent's Oesch class position - 8 classes"
label define class8_r ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_r class8_r
tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)
label variable class5_r "Respondent's Oesch class position - 5 classes"
label define  class5_r ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_r class5_r
tab class5_r


***************************************************************************************
* Partner's Oesch class position
* Recode and create variables used to construct class variable for partners
* Variables used to construct class variable for partners: iscocop, emprelp, emplnop
***************************************************************************************

**** Recode occupation variable (isco88 com 4-digit) for partners

tab iscocop

recode iscocop (missing=-9) if essround<6, copyrest gen(isco_partner)
label variable isco_partner "Current occupation of partner - isco88 4-digit" 
tab isco_partner

**** Recode employment status for partners

tab emprelp

recode emprelp (missing=9), copyrest gen(emplrel_p)
** SYNTAX H (France 2002 - partner):
recode emprlpfr02 (2 3 4=1)(1=2)(5=3)(6 8 9=9)
replace emplrel_p=emprlpfr02 if cntry=="FR" & essround==1
** SYNTAX J (France 2004 - partner):
recode emprlpfr04 (2 3 4=1)(1=2)(5=3)(6 8 9=9)
replace emplrel_p=emprlpfr04 if cntry=="FR" & essround==2
** SYNTAX F (Hungary 2004 - partner):
recode emprlphu (1 4=1)(2=2)(3=3)(6 7 8 9=9)
replace emplrel_p=emprlphu if cntry=="HU" & essround==2
label define emplrel_p ///
1 "Employee" ///
2 "Self-employed" ///
3 "Working for own family business" ///
9 "Missing"
label value emplrel_p emplrel_p
tab emplrel_p

tab emplnop

recode emplnop (0=0)(1/9=1)(10/10000=2)(missing=0), gen(emplno_p)
label define emplno_p ///
0 "0 employees" ///
1 "1-9 employees" ///
2 "10+ employees"
label value emplno_p emplno_p
tab emplno_p

gen selfem_partner=.
replace selfem_partner=1 if emplrel_p==1 | emplrel_p==9
replace selfem_partner=2 if emplrel_p==2 & emplno_p==0
replace selfem_partner=2 if emplrel_p==3
replace selfem_partner=3 if emplrel_p==2 & emplno_p==1
replace selfem_partner=4 if emplrel_p==2 & emplno_p==2
label variable selfem_partner "Employment status for partners"
label define selfem_partner ///
1 "Not self-employed" ///
2 "Self-empl without employees" ///
3 "Self-empl with 1-9 employees" ///
4 "Self-empl with 10 or more"
label value selfem_partner selfem_partner
tab selfem_partner


********************************************
* Create Oesch class schema for partners 
********************************************

gen class16_p = -9 if essround==1 | essround==2 | essround==3 | essround==4 | essround==5

* Large employers (1)

replace class16_p=1 if selfem_partner==4


* Self-employed professionals (2)

replace class16_p=2 if (selfem_partner==2 | selfem_partner==3) & (isco_partner >= 2000 & isco_partner <= 2229) 
replace class16_p=2 if (selfem_partner==2 | selfem_partner==3) & (isco_partner >= 2300 & isco_partner <= 2470)

* Small business owners with employees (3)

replace class16_p=3 if (selfem_partner==3) & (isco_partner >= 1000 & isco_partner <= 1999)
replace class16_p=3 if (selfem_partner==3) & (isco_partner >= 3000 & isco_partner <= 9333)
replace class16_p=3 if (selfem_partner==3) & (isco_partner == 2230)

* Small business owners without employees (4)

replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 1000 & isco_partner <= 1999)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 3000 & isco_partner <= 9333)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2230)

* Technical experts (5)

replace class16_p=5 if (selfem_partner==1) & (isco_partner >= 2100 & isco_partner <= 2213)

* Technicians (6)

replace class16_p=6 if (selfem_partner==1) & (isco_partner >= 3100 & isco_partner <= 3152)
replace class16_p=6 if (selfem_partner==1) & (isco_partner >= 3210 & isco_partner <= 3213)
replace class16_p=6 if (selfem_partner==1) & (isco_partner == 3434)

* Skilled manual (7)

replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 6000 & isco_partner <= 7442)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8310 & isco_partner <= 8312)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8324 & isco_partner <= 8330)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8332 & isco_partner <= 8340)

* Low-skilled manual (8)

replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 8000 & isco_partner <= 8300)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 8320 & isco_partner <= 8321)
replace class16_p=8 if (selfem_partner==1) & (isco_partner == 8331)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 9153 & isco_partner <= 9333)

* Higher-grade managers and administrators (9)

replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 1000 & isco_partner <= 1239)
replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 2400 & isco_partner <= 2429)
replace class16_p=9 if (selfem_partner==1) & (isco_partner == 2441)
replace class16_p=9 if (selfem_partner==1) & (isco_partner == 2470)

* Lower-grade managers and administrators (10)

replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 1300 & isco_partner <= 1319)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 3400 & isco_partner <= 3433)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 3440 & isco_partner <= 3450)

* Skilled clerks (11)

replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4000 & isco_partner <= 4112)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4114 & isco_partner <= 4210)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4212 & isco_partner <= 4222)

* Unskilled clerks (12)

replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4113)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4211)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4223)

* Socio-cultural professionals (13)

replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2220 &  isco_partner <= 2229)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2300 &  isco_partner <= 2320)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2340 &  isco_partner <= 2359)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2430 &  isco_partner <= 2440)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2442 &  isco_partner <= 2443)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2445)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2451)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2460)

* Socio-cultural semi-professionals (14)

replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2230)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2330 & isco_partner <= 2332)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2444)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2446 & isco_partner <= 2450)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2452 & isco_partner <= 2455)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3200)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3220 & isco_partner <= 3224)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3226)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3229 & isco_partner <= 3340)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3460 & isco_partner <= 3472)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3480)

* Skilled service (15)

replace class16_p=15 if (selfem_partner==1) & (isco_partner == 3225)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 3227 & isco_partner <= 3228)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 3473 & isco_partner <= 3475)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5000 & isco_partner <= 5113)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5122)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5131 & isco_partner <= 5132)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5140 & isco_partner <= 5141)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5143)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5160 & isco_partner <= 5220)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 8323)

* Low-skilled service (16)

replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5120 & isco_partner <= 5121)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5123 & isco_partner <= 5130)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5133 & isco_partner <= 5139)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5142)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5149)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5230)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 8322)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 9100 &  isco_partner <= 9152)

mvdecode class16_p, mv(-9)
label variable class16_p "Partner's Oesch class position - 16 classes"
label define class16_p ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16_p class16_p
tab class16_p

recode class16_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_p)
label variable class8_p "Partner's Oesch class position - 8 classes"
label define class8_p ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8_p class8_p
tab class8_p

recode class16_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_p)
label variable class5_p "Partner's Oesch class position - 5 classes"
label define  class5_p ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5_p class5_p
tab class5_p


****************************************************************************************************
* Final Oesch class position
* Merge two class variables (respondents and partners)
* Assign the partner's Oesch class position when the responant's Oesch class position is missing:
****************************************************************************************************

gen class16=class16_r

replace class16=class16_p if class16_r==.

label variable class16 "Final Oesch class position - 16 classes"
label define class16 ///
1 "Large employers" ///
2 "Self-employed professionals" ///
3 "Small business owners with employees" ///
4 "Small business owners without employees" ///
5 "Technical experts" ///
6 "Technicians" ///
7 "Skilled manual" ///
8 "Low-skilled manual" ///
9 "Higher-grade managers and administrators" ///
10 "Lower-grade managers and administrators" ///
11 "Skilled clerks" ///
12 "Unskilled clerks" ///
13 "Socio-cultural professionals" ///
14 "Socio-cultural semi-professionals" ///
15 "Skilled service" ///
16 "Low-skilled service"
label value class16 class16
tab class16

recode class16 (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8)
label variable class8 "Final Oesch class position - 8 classes"
label define class8 ///
1 "Self-employed professionals and large employers" ///
2 "Small business owners" ///
3 "Technical (semi-)professionals" ///
4 "Production workers" ///
5 "(Associate) managers" ///
6 "Clerks" ///
7 "Socio-cultural (semi-)professionals" ///
8 "Service workers"
label value class8 class8
tab class8

recode class16 (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5)
label variable class5 "Final Oesch class position - 5 classes"
label define class5 ///
1 "Higher-grade service class" ///
2 "Lower-grade service class" ///
3 "Small business owners" ///
4 "Skilled workers" ///
5 "Unskilled workers"
label value class5 class5
tab class5


drop isco_mainjob emplrel_r emplno_r selfem_mainjob  isco_partner emplrel_p emplno_p selfem_partner

drop class16_r class8_r class5_r  class16_p class8_p class5_p

replace class16=. if essround>=6
replace class8=. if essround>=6
replace class5=. if essround>=6


*WAVES 6-7-8

*********************************************************************************************************************************************
* OESCH CLASS SCHEMA
* Create 16-Class schema, 8-Class schema and 5-Class schema
*********************************************************************************************************************************************

**** 16-Class schema constructed
  *1 Large employers
  *2 Self-employed professionals
  *3 Small business owners with employees
  *4 Small business owners without employees
  *5 Technical experts
  *6 Technicians
  *7 Skilled manual
  *8 Low-skilled manual
  *9 Higher-grade managers and administrators
  *10 Lower-grade managers and administrators
  *11 Skilled clerks
  *12 Unskilled clerks
  *13 Socio-cultural professionals
  *14 Socio-cultural semi-professionals
  *15 Skilled service
  *16 Low-skilled service

**** 8-Class schema constructed
  *1 Self-employed professionals and large employers
  *2 Small business owners
  *3 Technical (semi-)professionals
  *4 Production workers
  *5 (Associate) managers
  *6 Clerks
  *7 Socio-cultural (semi-)professionals
  *8 Service workers

**** 5-Class schema constructed
  *1 Higher-grade service class
  *2 Lower-grade service class
  *3 Small business owners
  *4 Skilled workers
  *5 Unskilled workers
  
**** WARNING: before you execute this syntax, you have to execute the "ESS_miss.do" syntax file that accompanies the ESS round 6 - 2012 file

**** Variables used to construct Oesch class schema: isco08, emplrel, emplno, isco08p, emprelp

****************************************************************************************
* Respondent's Oesch class position
* Recode and create variables used to construct class variable for respondents
* Variables used to construct class variable for respondents: isco08, emplrel, emplno
****************************************************************************************

**** Recode occupation variable (isco08 com 4-digit) for respondents

tab isco08

recode isco08 (missing=-9) if essround>=6, copyrest gen(isco_mainjob)
label variable isco_mainjob "Current occupation of respondent - isco88 4-digit"
tab isco_mainjob

**** Recode employment status for respondents

tab emplrel 

recode emplrel (missing=9), copyrest gen(emplrel_r)

tab emplrel_r

tab emplno

recode emplno (0=0)(1/9=1)(10/10000=2)(missing=0), gen(emplno_r)

tab emplno_r

gen selfem_mainjob=.
replace selfem_mainjob=1 if emplrel_r==1 | emplrel_r==9
replace selfem_mainjob=2 if emplrel_r==2 & emplno_r==0
replace selfem_mainjob=2 if emplrel_r==3
replace selfem_mainjob=3 if emplrel_r==2 & emplno_r==1
replace selfem_mainjob=4 if emplrel_r==2 & emplno_r==2
label variable selfem_mainjob "Employment status for respondants"

tab selfem_mainjob


*************************************************
* Create Oesch class schema for respondents
*************************************************

gen class16_r = -9 if essround>=6

* Large employers (1)

replace class16_r=1 if selfem_mainjob==4

* Self-employed professionals (2)

replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2000 & isco_mainjob <= 2162) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2164 & isco_mainjob <= 2165) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2200 & isco_mainjob <= 2212) 
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob == 2250)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2261 & isco_mainjob <= 2262)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2300 & isco_mainjob <= 2330)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2350 & isco_mainjob <= 2352)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2359 & isco_mainjob <= 2432)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2500 & isco_mainjob <= 2619)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob == 2621)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2630 & isco_mainjob <= 2634)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2636 & isco_mainjob <= 2640)
replace class16_r=2 if (selfem_mainjob==2 | selfem_mainjob==3) & (isco_mainjob >= 2642 & isco_mainjob <= 2643)

* Small business owners with employees (3)

replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 1000 & isco_mainjob <= 1439)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2163)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2166)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2220 & isco_mainjob <= 2240)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2260)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2263 & isco_mainjob <= 2269)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2340 & isco_mainjob <= 2342)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2353 & isco_mainjob <= 2356)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2433 & isco_mainjob <= 2434)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2620)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2622)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2635)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob == 2641)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 2650 & isco_mainjob <= 2659)
replace class16_r=3 if (selfem_mainjob==3) & (isco_mainjob >= 3000 & isco_mainjob <= 9629)

* Small business owners without employees (4)

replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 1000 & isco_mainjob <= 1439)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2163)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2166)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2220 & isco_mainjob <= 2240)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2260)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2263 & isco_mainjob <= 2269)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2340 & isco_mainjob <= 2342)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2353 & isco_mainjob <= 2356)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2433 & isco_mainjob <= 2434)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2620)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2622)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2635)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob == 2641)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 2650 & isco_mainjob <= 2659)
replace class16_r=4 if (selfem_mainjob==2) & (isco_mainjob >= 3000 & isco_mainjob <= 9629)

* Technical experts (5)

replace class16_r=5 if (selfem_mainjob==1) & (isco_mainjob >= 2100 & isco_mainjob <= 2162)
replace class16_r=5 if (selfem_mainjob==1) & (isco_mainjob >= 2164 & isco_mainjob <= 2165)
replace class16_r=5 if (selfem_mainjob==1) & (isco_mainjob >= 2500 & isco_mainjob <= 2529)

* Technicians (6)

replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3100 & isco_mainjob <= 3155)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3210 & isco_mainjob <= 3214)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob == 3252)
replace class16_r=6 if (selfem_mainjob==1) & (isco_mainjob >= 3500 & isco_mainjob <= 3522)

* Skilled manual (7)

replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 6000 & isco_mainjob <= 7549)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8310 & isco_mainjob <= 8312)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob == 8330)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8332 & isco_mainjob <= 8340)
replace class16_r=7 if (selfem_mainjob==1) & (isco_mainjob >= 8342 & isco_mainjob <= 8344)

* Low-skilled manual (8)

replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8000 & isco_mainjob <= 8300)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 8320 & isco_mainjob <= 8321)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob == 8341)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob == 8350)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 9200 & isco_mainjob <= 9334)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 9600 & isco_mainjob <= 9620)
replace class16_r=8 if (selfem_mainjob==1) & (isco_mainjob >= 9622 & isco_mainjob <= 9629)

* Higher-grade managers and administrators (9)

replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 1000 & isco_mainjob <= 1300)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 1320 & isco_mainjob <= 1349)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 2400 & isco_mainjob <= 2432)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 2610 & isco_mainjob <= 2619)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob == 2631)
replace class16_r=9 if (selfem_mainjob==1) & (isco_mainjob >= 100 & isco_mainjob <= 110)

* Lower-grade managers and administrators (10)

replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 1310 & isco_mainjob <= 1312)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 1400 & isco_mainjob <= 1439)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 2433 & isco_mainjob <= 2434)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3300 & isco_mainjob <= 3339)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob == 3343)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 3350 & isco_mainjob <= 3359)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob == 3411)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob == 5221)
replace class16_r=10 if (selfem_mainjob==1) & (isco_mainjob >= 200 & isco_mainjob <= 210)

* Skilled clerks (11)

replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 3340 & isco_mainjob <= 3342)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob == 3344)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4000 & isco_mainjob <= 4131)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4200 & isco_mainjob <= 4221)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4224 & isco_mainjob <= 4413)
replace class16_r=11 if (selfem_mainjob==1) & (isco_mainjob >= 4415 & isco_mainjob <= 4419)

* Unskilled clerks (12)

replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4132)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4222)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 4223)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 5230)
replace class16_r=12 if (selfem_mainjob==1) & (isco_mainjob == 9621)

* Socio-cultural professionals (13)

replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2200 &  isco_mainjob <= 2212)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2250)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2261 &  isco_mainjob <= 2262)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2300 &  isco_mainjob <= 2330)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2350 &  isco_mainjob <= 2352)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2359)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2600)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2621)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob == 2630)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2632 &  isco_mainjob <= 2634)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2636 &  isco_mainjob <= 2640)
replace class16_r=13 if (selfem_mainjob==1) & (isco_mainjob >= 2642 &  isco_mainjob <= 2643)

* Socio-cultural semi-professionals (14)

replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2163)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2166)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2220 & isco_mainjob <= 2240)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2260)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2263 & isco_mainjob <= 2269)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2340 & isco_mainjob <= 2342)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2353 & isco_mainjob <= 2356)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2620)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2622)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2635)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 2641)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 2650 & isco_mainjob <= 2659)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3200)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3220 & isco_mainjob <= 3230)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3250)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3253 & isco_mainjob <= 3257)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3259)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3400 & isco_mainjob <= 3410)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3412 & isco_mainjob <= 3413)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob >= 3430 & isco_mainjob <= 3433)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 3435)
replace class16_r=14 if (selfem_mainjob==1) & (isco_mainjob == 4414)

* Skilled service (15)

replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3240)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3251)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3258)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 3420 & isco_mainjob <= 3423)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 3434)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5000 & isco_mainjob <= 5120)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5140 & isco_mainjob <= 5142)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5163)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5165)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5200)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5220)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5222 & isco_mainjob <= 5223)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5241 & isco_mainjob <= 5242)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5300 & isco_mainjob <= 5321)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob >= 5400 & isco_mainjob <= 5413)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 5419)
replace class16_r=15 if (selfem_mainjob==1) & (isco_mainjob == 8331)

* Low-skilled service (16)

replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5130 & isco_mainjob <= 5132)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5150 & isco_mainjob <= 5162)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5164)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5169)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5210 & isco_mainjob <= 5212)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5240)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5243 & isco_mainjob <= 5249)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 5322 & isco_mainjob <= 5329)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 5414)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob == 8322)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 9100 & isco_mainjob <= 9129)
replace class16_r=16 if (selfem_mainjob==1) & (isco_mainjob >= 9400 & isco_mainjob <= 9520)

mvdecode class16_r, mv(-9)


recode class16_r (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_r)

tab class8_r

recode class16_r (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_r)

tab class5_r


***************************************************************************************
* Partner's Oesch class position
* Recode and create variables used to construct class variable for partners
* Variables used to construct class variable for partners: isco08p, emprelp
***************************************************************************************

**** Recode occupation variable (isco88 com 4-digit) for partners

tab isco08p

recode isco08p (missing=-9) if essround>=6, copyrest gen(isco_partner)
label variable isco_partner "Current occupation of partner - isco88 4-digit" 
tab isco_partner

**** Recode employment status for partners

tab emprelp

recode emprelp (1=1)(2 3=2)(missing=1), gen(selfem_partner)
label variable selfem_partner "Employment status for partners"

tab selfem_partner

********************************************
* Create Oesch class schema for partners 
********************************************

gen class16_p = -9 if essround>=6

* Large employers (1)



* Self-employed professionals (2)

replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2000 & isco_partner <= 2162)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2164 & isco_partner <= 2165)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2200 & isco_partner <= 2212)
replace class16_p=2 if (selfem_partner==2) & (isco_partner == 2250)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2261 & isco_partner <= 2262)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2300 & isco_partner <= 2330)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2350 & isco_partner <= 2352)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2359 & isco_partner <= 2432)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2500 & isco_partner <= 2619)
replace class16_p=2 if (selfem_partner==2) & (isco_partner == 2621)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2630 & isco_partner <= 2634)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2636 & isco_partner <= 2640)
replace class16_p=2 if (selfem_partner==2) & (isco_partner >= 2642 & isco_partner <= 2643)

* Small business owners with employees (3)
 


* Small business owners without employees (4)

replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 1000 & isco_partner <= 1439)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2163)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2166)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2220 & isco_partner <= 2240)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2260)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2263 & isco_partner <= 2269)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2340 & isco_partner <= 2342)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2353 & isco_partner <= 2356)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2433 & isco_partner <= 2434)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2620)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2622)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2635)
replace class16_p=4 if (selfem_partner==2) & (isco_partner == 2641)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 2650 & isco_partner <= 2659)
replace class16_p=4 if (selfem_partner==2) & (isco_partner >= 3000 & isco_partner <= 9629)

* Technical experts (5)

replace class16_p=5 if (selfem_partner==1) & (isco_partner >= 2100 & isco_partner <= 2162)
replace class16_p=5 if (selfem_partner==1) & (isco_partner >= 2164 & isco_partner <= 2165)
replace class16_p=5 if (selfem_partner==1) & (isco_partner >= 2500 & isco_partner <= 2529)

* Technicians (6)

replace class16_p=6 if (selfem_partner==1) & (isco_partner >= 3100 & isco_partner <= 3155)
replace class16_p=6 if (selfem_partner==1) & (isco_partner >= 3210 & isco_partner <= 3214)
replace class16_p=6 if (selfem_partner==1) & (isco_partner == 3252)
replace class16_p=6 if (selfem_partner==1) & (isco_partner >= 3500 & isco_partner <= 3522)

* Skilled manual (7)

replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 6000 & isco_partner <= 7549)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8310 & isco_partner <= 8312)
replace class16_p=7 if (selfem_partner==1) & (isco_partner == 8330)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8332 & isco_partner <= 8340)
replace class16_p=7 if (selfem_partner==1) & (isco_partner >= 8342 & isco_partner <= 8344)

* Low-skilled manual (8)

replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 8000 & isco_partner <= 8300)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 8320 & isco_partner <= 8321)
replace class16_p=8 if (selfem_partner==1) & (isco_partner == 8341)
replace class16_p=8 if (selfem_partner==1) & (isco_partner == 8350)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 9200 & isco_partner <= 9334)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 9600 & isco_partner <= 9620)
replace class16_p=8 if (selfem_partner==1) & (isco_partner >= 9622 & isco_partner <= 9629)

* Higher-grade managers and administrators (9)

replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 1000 & isco_partner <= 1300)
replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 1320 & isco_partner <= 1349)
replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 2400 & isco_partner <= 2432)
replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 2610 & isco_partner <= 2619)
replace class16_p=9 if (selfem_partner==1) & (isco_partner == 2631)
replace class16_p=9 if (selfem_partner==1) & (isco_partner >= 100 & isco_partner <= 110)

* Lower-grade managers and administrators (10)


replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 1310 & isco_partner <= 1312)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 1400 & isco_partner <= 1439)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 2433 & isco_partner <= 2434)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 3300 & isco_partner <= 3339)
replace class16_p=10 if (selfem_partner==1) & (isco_partner == 3343)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 3350 & isco_partner <= 3359)
replace class16_p=10 if (selfem_partner==1) & (isco_partner == 3411)
replace class16_p=10 if (selfem_partner==1) & (isco_partner == 5221)
replace class16_p=10 if (selfem_partner==1) & (isco_partner >= 200 & isco_partner <= 210)

* Skilled clerks (11)

replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 3340 & isco_partner <= 3342)
replace class16_p=11 if (selfem_partner==1) & (isco_partner == 3344)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4000 & isco_partner <= 4131)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4200 & isco_partner <= 4221)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4224 & isco_partner <= 4413)
replace class16_p=11 if (selfem_partner==1) & (isco_partner >= 4415 & isco_partner <= 4419)

* Unskilled clerks (12)

replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4132)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4222)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 4223)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 5230)
replace class16_p=12 if (selfem_partner==1) & (isco_partner == 9621)

* Socio-cultural professionals (13)

replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2200 & isco_partner <= 2212)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2250)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2261 & isco_partner <= 2262)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2300 & isco_partner <= 2330)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2350 & isco_partner <= 2352)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2359)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2600)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2621)
replace class16_p=13 if (selfem_partner==1) & (isco_partner == 2630)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2632 & isco_partner <= 2634)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2636 & isco_partner <= 2640)
replace class16_p=13 if (selfem_partner==1) & (isco_partner >= 2642 & isco_partner <= 2643)

* Socio-cultural semi-professionals (14)

replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2163)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2166)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2220 & isco_partner <= 2240)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2260)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2263 & isco_partner <= 2269)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2340 & isco_partner <= 2342)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2353 & isco_partner <= 2356)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2620)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2622)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2635)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 2641)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 2650 & isco_partner <= 2659)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3200)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3220 & isco_partner <= 3230)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3250)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3253 & isco_partner <= 3257)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3259)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3400 & isco_partner <= 3410)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3412 & isco_partner <= 3413)
replace class16_p=14 if (selfem_partner==1) & (isco_partner >= 3430 & isco_partner <= 3433)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 3435)
replace class16_p=14 if (selfem_partner==1) & (isco_partner == 4414)

* Skilled service (15)

replace class16_p=15 if (selfem_partner==1) & (isco_partner == 3240)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 3251)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 3258)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 3420 & isco_partner <= 3423)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 3434)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5000 & isco_partner <= 5120)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5140 & isco_partner <= 5142)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5163)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5165)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5200)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5220)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5222 & isco_partner <= 5223)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5241 & isco_partner <= 5242)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5300 & isco_partner <= 5321)
replace class16_p=15 if (selfem_partner==1) & (isco_partner >= 5400 & isco_partner <= 5413)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 5419)
replace class16_p=15 if (selfem_partner==1) & (isco_partner == 8331)

* Low-skilled service (16)

replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5130 & isco_partner <= 5132)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5150 & isco_partner <= 5162)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5164)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5169)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5210 & isco_partner <= 5212)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5240)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5243 & isco_partner <= 5249)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 5322 & isco_partner <= 5329)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 5414)
replace class16_p=16 if (selfem_partner==1) & (isco_partner == 8322)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 9100 & isco_partner <= 9129)
replace class16_p=16 if (selfem_partner==1) & (isco_partner >= 9400 & isco_partner <= 9520)

mvdecode class16_p, mv(-9)

tab class16_p

recode class16_p (1 2=1)(3 4=2)(5 6=3)(7 8=4)(9 10=5)(11 12=6)(13 14=7)(15 16=8), gen(class8_p)
tab class8_p

recode class16_p (1 2 5 9 13=1)(6 10 14=2)(3 4=3)(7 11 15=4)(8 12 16=5), gen(class5_p)

tab class5_p

****************************************************************************************************
* Final Oesch class position
* Merge two class variables (respondents and partners)
* Assign the partner's Oesch class position when the responant's Oesch class position is missing:
****************************************************************************************************

replace class16=class16_r if essround>=6

replace class16=class16_p if class16_r==. & essround>=6

tab class16

replace class8=1 if (class16==1 | class16==2) & essround>=6
replace class8=2 if (class16==3 | class16==4) & essround>=6
replace class8=3 if (class16==5 | class16==6) & essround>=6
replace class8=4 if (class16==7 | class16==8) & essround>=6
replace class8=5 if (class16==9 | class16==10) & essround>=6
replace class8=6 if (class16==11 | class16==12) & essround>=6
replace class8=7 if (class16==13 | class16==14) & essround>=6
replace class8=8 if (class16==15 | class16==18) & essround>=6


tab class8

replace class5=1 if (class16==1 | class16==2 | class16==5 | class16==9 | class16==13) & essround>=6
replace class5=2 if (class16==6 | class16==10 | class16==14) & essround>=6
replace class5=3 if (class16==3 | class16==4) & essround>=6
replace class5=4 if (class16==7 | class16==11 | class16==15) & essround>=6
replace class5=5 if (class16==8 | class16==12 | class16==16) & essround>=6

tab class5


drop isco_mainjob emplrel_r emplno_r selfem_mainjob  isco_partner selfem_partner

drop class16_r class8_r class5_r  class16_p class8_p class5_p




********************************************************************************
********************************************************************************
*generate variables for analysis
********************************************************************************
********************************************************************************

gen COUNTRY=.
replace COUNTRY=82601 if cntry=="GB"
replace COUNTRY=276 if cntry=="DE"
replace COUNTRY=756 if cntry=="CH"
replace COUNTRY=752 if cntry=="SE"
replace COUNTRY=578 if cntry=="NO"
replace COUNTRY=616 if cntry=="PL"
replace COUNTRY=348 if cntry=="HU"

gen country_geo=""
replace country_geo="FR" if cntry=="FR"
replace country_geo="DE" if cntry=="DE"


gen YEAR=.
replace YEAR=2002 if essround==1
replace YEAR=2004 if essround==2
replace YEAR=2006 if essround==3
replace YEAR=2008 if essround==4
replace YEAR=2010 if essround==5
replace YEAR=2012 if essround==6
replace YEAR=2014 if essround==7
replace YEAR=2016 if essround==8
replace YEAR=2018 if essround==9


gen STFLIFE100=stflife*10
gen HAPPY100=happy*10

tab STFLIFE100 stflife, m
tab HAPPY100 happy, m

gen AGE=agea

gen SEX01=.
replace SEX01=1 if gndr==1
replace SEX01=0 if gndr==2
label define SEX01 1"male" 0"female"
label value SEX01 SEX01

gen ed_level=.
replace ed_level=1 if edulvla==1 | edulvla==2
replace ed_level=2 if edulvla==3 |edulvla==4 
replace ed_level=3 if  edulvla==5 
label variable ed_level "three levels for respondent education"
label define ed_level 1 "less than lower secondary education" 2 "upper secondary and post-upper secondary education" 3 "tertiary university education", replace
label value ed_level ed_level
fre ed_level


********************************************************************************
save "$path\ESS_dataset_2002-2018_ready.dta", replace

erase "$path\ESS_dataset_2002-2018.dta"
erase "$path\ESS2csHU_1.dta"
erase "$path\2004_FR_specific.dta"
erase "$path\2002_FR_speficic.dta"

